/*
	Copyright 2008 Jay Elliott

	This file is part of libemath.

	libemath is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	libemath is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with libemath.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CALIGNEDBOX_H_
#define __CALIGNEDBOX_H_

#include <cstdio>

#include "macros.h"
#include "cPoint3d.h"

namespace emath
{

class cAlignedBox
{
private:
	cPoint3d pos, ext;

public:
	inline cAlignedBox(const cPoint3d& loc, const cPoint3d& extents);

	bool intersects(cAlignedBox other);

	inline void GetPoints(cPoint3d buffer[8]) const;
	
	inline cPoint3d GetPos(void);
	inline cPoint3d GetExt(void);
};

cAlignedBox::cAlignedBox(const cPoint3d& loc, const cPoint3d& extents)
{
	pos = loc;
	ext = extents;
}

void cAlignedBox::GetPoints(cPoint3d buffer[8]) const
{
	buffer[0] = cPoint3d(pos.x - ext.x, pos.y - ext.y, pos.z - ext.z);
	buffer[1] = cPoint3d(pos.x - ext.x, pos.y - ext.y, pos.z + ext.z);
	buffer[2] = cPoint3d(pos.x - ext.x, pos.y + ext.y, pos.z - ext.z);
	buffer[3] = cPoint3d(pos.x - ext.x, pos.y + ext.y, pos.z + ext.z);

	buffer[4] = cPoint3d(pos.x + ext.x, pos.y - ext.y, pos.z - ext.z);
	buffer[5] = cPoint3d(pos.x + ext.x, pos.y - ext.y, pos.z + ext.z);
	buffer[6] = cPoint3d(pos.x + ext.x, pos.y + ext.y, pos.z - ext.z);
	buffer[7] = cPoint3d(pos.x + ext.x, pos.y + ext.y, pos.z + ext.z);
}

cPoint3d cAlignedBox::GetPos(void)
{
         return pos;
}

cPoint3d cAlignedBox::GetExt(void)
{
         return ext;
}


}
#endif
